<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>jsdk</title>
    <script src="//cdn.bootcss.com/eruda/1.5.2/eruda.min.js"></script>
    <script src="https://res2.wx.qq.com/open/js/jweixin-1.6.0.js"></script>
    <script>
      eruda.init();
    </script>

    <!-- <script src="./libs/xhr.js"></script> -->
  </head>
  <body>
    <button onclick="refresh()">刷新</button>
    <button onclick="navigateBack()">返回小程序</button>
    <button onclick="switchTab({url:'/pages/invoice/invList/invList'})">
      跳转小程序首页（switch）
    </button>
    <button
      onclick="navigateTo({url:'/pages/mine/myCompany/myCompany',complete(err){console.log(err)}})"
    >
      navigateTo
    </button>
    <button onClick="tradePay()">支付</button>
    <button onClick="scanCode()">扫一扫</button>
    <button onClick="chooseImage()">拍照</button>
    <button onClick="getEnv()">获取当前环境</button>
    <button onClick="navigateToMiniProgram()">小程序跳转</button>
    <button onClick="reLunch()">小程序跳转reLunch</button>
    <script>
      // 刷新
      function refresh() {
        window.location.reload();
      }
      function scanCode() {
        miniJSDK.scanQRCode({
          success(res) {
            console.log(res);
          }
        });
      }

      function tradePay() {
        miniJSDK.tradePay({
          callbackUrl:
            "http://172.30.5.40:8080?token=ed4a85fa453645fb9fac43afcd3499ff&ismini=y#/cmss/12",
          payStr:
            '{"timeStamp":"1584087315","package":"prepay_id=wx13161515615638f31cf3638a1125681300","paySign":"UP3+NDRO7JBATtsZriPQD0m1EeJO/0NUpb4zFaTch1hI+E6om58vpbU/8SlZlfzFE8GmieBLte77Np5G29qbGXKwuZFxxtQ1iiU3rW8+JQ8shs2d6nBUoHjc0LmQ902e7uC0H3Q5+we/IHccKjT5tMSTSobtRZHfyKlNyL2AWst/Fp0tTE3VjMPAyP3mu2ytlcYLSVrpn9agNAikMfogpAqzK8ASnnLybtByUf5fLAX467e4JOxeVBB6nZrZRVXJFriMNC9mkiUA5IjuCeB2EZ2AxF+W0gyB5WYccv6nYiSjwLqalEvX4OEXkXjALAVtiA8dUiPqYU2CI/UBavySbQ==","appId":"wx179d5238603fea4a","signType":"RSA","nonceStr":"74bd59e4080d4780a862b0a051845c1a"}'
        });
      }

      function navigateToMiniProgram() {
        miniJSDK.navigateToMiniProgram({
          path: "/pages/asa/asa",
          appId: "wx9db2c16d0633c2e7",
          success() {},
          fail() {},
          complete() {}
        });
      }
      function getEnv() {
        miniJSDK.getEnv(res => {
          console.log(res);
        });
      }

      //
      function chooseImage() {
        wx.chooseImage({
          count: 1, // 默认9
          sizeType: ["original", "compressed"], // 可以指定是原图还是压缩图，默认二者都有
          sourceType: ["album", "camera"], // 可以指定来源是相册还是相机，默认二者都有
          success: function (res) {
            console.log(res);
            var localIds = res.localIds; // 返回选定照片的本地ID列表，localId可以作为img标签的src属性显示图片
          },
          fail(err) {
            console.warn(err);
          }
        });
      }

      function navigateBack() {
        console.log(window.wx);
        var miniJSDK = miniSDK(window.wx);
        miniJSDK.navigateBack();
      }

      function switchTab({ url, success, fail, complete }) {
        miniJSDK.switchTab({
          url: url
        });
      }

      function navigateTo({ url, success, fail, complete }) {
        miniJSDK.navigateTo({
          url,
          fail,
          complete
        });
      }

      function reLunch() {
        miniJSDK.reLaunch({
          url: "/pages/pay/pay",
          fail: () => {},
          complete: () => {}
        });
      }

      function redirectTo({ url, success, fail, complete }) {
        miniJSDK.redirectTo({
          url,
          fail,
          complete
        });
      }
    </script>
    <script id="mini-jsdk" src="./lib/umd/mini-jsdk.dev.js"></script>
  </body>
</html>
